document.addEventListener('DOMContentLoaded', function () {
    // 密码显示/隐藏切换
    const togglePassword = document.getElementById('togglePassword');
    const passwordInput = document.getElementById('password');
    const errorMessage = document.getElementById('errorMessage');

    togglePassword.addEventListener('click', function () {
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);
        this.textContent = type === 'password' ? '👁️' : '👁️‍🗨️';
    });

    // 登录表单提交处理
    const loginForm = document.getElementById('loginForm');
    loginForm.addEventListener('submit', function (e) {
        e.preventDefault();

        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        // 验证用户名和密码
        if (username === 'xiaomeifang' && password === '123456') {
            // 登录成功
            errorMessage.style.display = 'none';
            alert('登录成功！即将跳转到主页');
            window.location.href = './html/index.html';
        } else {
            // 登录失败
            errorMessage.style.display = 'block';
            loginForm.classList.add('shake');
            setTimeout(() => {
                loginForm.classList.remove('shake');
            }, 500);
        }
    });
});